﻿using CfgTable;
using IQIGame.Onigao.Framework;

namespace IQIGame.Onigao.GamePlay
{
    public class UD_GMCmd : IReusableClass
    {
        public int cid { get; private set; }
        public string cmdValue { get; private set; }
        public CfgGmCmd cfgCmd { get; private set; }

        public string name { get; private set; }
        public string cmd => cfgCmd.Cmd;


        public UD_GMCmd Sync(CfgGmCmd cfgData, string cmdValue = null, string name = null, int cid = 0)
        {
            this.cfgCmd = cfgData;
            if (cmdValue == null)
            {
                cmdValue = cfgCmd.DefaultParam;
            }

            this.cmdValue = cmdValue;
            if (name == null)
            {
                name = cfgCmd.Name;
            }
            this.name = name;

            this.cmdValue = cmdValue;
            if (cid == 0)
            {
                cid = cfgCmd.Id;
            }
            this.cid = cid;
            return this;
        }

        public bool IsContains(string filter)
        {
            if (string.IsNullOrEmpty(filter))
            {
                return false;
            }
            string str = this.cid.ToString();
            if (str.Contains(filter))
            {
                return true;
            }
            if (this.name.Contains(filter))
            {
                return true;
            }
            if (this.cmd.Contains(filter))
            {
                return true;
            }
            return false;
        }

        public void Clear()
        {
            this.cid = 0;
            this.cfgCmd = null;
            this.cmdValue = null;
            this.name = null;
        }

        #region 对象池
        public uint MaxStore => 10;

        public void OnReset()
        {
            this.Clear();
        }

        public void Put2Pool()
        {
            ClassPool.Put(this); // 无继承
        }

        static public UD_GMCmd NewFromPool()
        {
            return ClassPool<UD_GMCmd>.Get();
        }
        #endregion

    }
}
